package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.DonateDao;

import bean.Donate;

public class WriteModifyDonateServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Donate donate = new Donate();
		String id = req.getParameter("modifyDonateId");
		donate.setDonate_name(req.getParameter("modifyDonateName"));
		donate.setDonate_price(req.getParameter("modifyDonatePrice"));
		donate.setDonate_need(req.getParameter("choice_project_title"));
		donate.setDonate_email(req.getParameter("modifyDonateEmail"));
		donate.setDonate_telephone(req.getParameter("modifyDonateTelephone"));
		donate.setDonate_address(req.getParameter("modifyDonateAddress"));
		donate.setDonate_postalcode(req.getParameter("modifyDonatePostalcode"));
		donate.setDonate_alumni(req.getParameter("modifyDonateAlumni"));
		String modifyDonateClassInformation = null;
		if ("yes".equals(donate.getDonate_alumni())) {
			modifyDonateClassInformation = req
					.getParameter("modifyDonateClassInformation");
		}
		donate.setDonate_classInformation(modifyDonateClassInformation);
		donate.setRemark(req.getParameter("modifyDonateRemark"));

		int num = new DonateDao().writeModifyInfo(id, donate);
		HttpSession session = req.getSession();
		String choice_id = (String) session.getAttribute("choice_id");

		if (num == 1) {
			session.setAttribute("find_insert_id", 7);
		} else {
			session.setAttribute("find_insert_id", 8);
		}

		resp.sendRedirect("houtai/guanli_1.jsp?id=" + choice_id);
	}

}
